package com.gxuwz.attend.service;

import com.gxuwz.attend.dao.LoginDao;
import com.gxuwz.attend.entity.Admin;

import java.util.Collections;
import java.util.List;

/**
 * 用户管理Service类， 封装表示业务逻辑处理的成员方法
 * @author amu_1115@126.com
 */
public class LoginService {
    private LoginDao userDao;


    public boolean deleteUser(String userid){
       int rs= userDao.delete(userid);
       if (rs==0){
           return false;
       }else {
           return true;
       }
    }
    public Object login(String username, String password, String role) {
        switch (role) {
            case "admin":
                return userDao.loginAdmin(username, password);
            case "instructor":
                return userDao.loginInstructor(username, password);
            case "student":
                return userDao.loginStudent(username, password);
            default:
                return null;
        }
    }


    public void setUserDao(LoginDao userDao) {
        this.userDao = userDao;
    }

    public List<Admin> getAllUsers(int size, int offset) {
        List<Admin> admins = userDao.getAllUsers(size,offset);

       if (admins !=null&&!admins.isEmpty()){
           System.out.println("成功");
           return admins;
       }else {

           System.out.println("失败");
           return Collections.emptyList(); // 返回空列表
       }

    }

    public List<Admin> findUsersByUsername(String username, int size, int offset) {
        return userDao.findUsersByUsername(username,size,offset);
    }
}
